﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Donators_CRUD_Demo
{
    class Program
    {
        static void Main(string[] args)
        {
            using (var db = new DonatorsContext())
            {
                //var donators = from d in db.Donators
                //               where d.Amount == 50m
                //               select d;
                //Console.WriteLine("Id\t姓名\t金额\t打赏日期");

                //foreach (var donator in donators)
                //{
                //    Console.WriteLine("{0}\t{1}\t{2}\t{3}", donator.Id, donator.Name, donator.Amount, donator.DonateDate.ToShortDateString());
                //}

                var ds = from p in db.Provinces
                         where p.ProvinceName == "山东省"
                         from d in p.Donators
                         select d;

                foreach (var donator in ds)
                {
                    Console.WriteLine("{0}\t{1}\t{2}\t{3}", donator.Id, donator.Name, donator.Amount, donator.DonateDate.ToShortDateString());
                }


                var province = from donator in db.Donators
                               where donator.Name == "雪茄"
                               select donator.Province;

                foreach (var item in province)
                {
                    Console.WriteLine(item.ProvinceName);
                }

                ds = from d in db.Donators
                     where d.Amount > 10 && d.Amount < 20
                     select d;

                foreach (var donator in ds)
                {
                    Console.WriteLine("{0}\t{1}\t{2}\t{3}", donator.Id, donator.Name, donator.Amount, donator.DonateDate.ToShortDateString());
                }
            }

            Console.WriteLine("Operation completed!");
            Console.Read();
        }
    }
}
